home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / others / ole_101.zip / SCHMOO.ZIP / CLIP.C next >
C/C++ Source or Header  |  1992-04-13  |  6KB  |  267 lines

  1. /*
  2.  * CLIP.C
  3.  *
  4.  * Functions to interact with the clipboard.
  5.  *
  6.  * Copyright(c) Microsoft Corp. 1992 All Rights Reserved
  7.  *
  8.  */
  9.  
  10. #include <windows.h>
  11. #include <ole.h>
  12. #include "schmoo.h"
  13. #include "oleglobl.h"
  14.  
  15.  
  16.  
  17. /*
  18.  * FEditCut
  19.  *
  20.  * Purpose:
  21.  *  Places a private format, a metafile, and a bitmap of the display
  22.  *  on the clipboard and clears the editor window with the equivalent
  23.  *  to complete the "Cut" operation.  This operation also sets the
  24.  *  dirty flag through a call to FDirtySet.
  25.  *
  26.  * Parameters:
  27.  *  pGlob           LPGLOBALS to the global variable block.
  28.  *
  29.  * Return Value:
  30.  *  BOOL            TRUE if successful, FALSE otherwise.
  31.  *
  32.  */
  33.  
  34. BOOL FAR PASCAL FEditCut(LPGLOBALS pGlob)
  35.     {
  36.     //Copy editor contents to the clipboard.
  37.     if (!FEditCopy(pGlob, TRUE))
  38.         return FALSE;
  39.  
  40.     //Clear out the editor contents.
  41.     SendMessage(pGlob->hWndPolyline, PLM_POLYLINENEW, 0, 0L);
  42.     FDirtySet(TRUE);
  43.     return TRUE;
  44.     }
  45.  
  46.  
  47.  
  48. /*
  49.  * FEditCopy
  50.  *
  51.  * Purpose:
  52.  *  Places a private format, a metafile, and a bitmap of the display
  53.  *  on the clipboard.
  54.  *
  55.  *
  56.  * Parameters:
  57.  *  pGlob           LPGLOBALS to the global variable block.
  58.  *  fCut            BOOL indicating if this copy is part of a Cut.
  59.  *
  60.  * Return Value:
  61.  *  BOOL            TRUE if anything was successfully placed on the
  62.  *                  clipboard, FALSE otherwise.
  63.  *
  64.  */
  65.  
  66. BOOL FAR PASCAL FEditCopy(LPGLOBALS pGlob, BOOL fCut)
  67.     {
  68.     BOOL            fRet=TRUE;
  69.     HANDLE          hMem;
  70.  
  71.     //Attempt to gain clipboard ownership.
  72.     if (!OpenClipboard(pGlob->hWnd))
  73.         return FALSE;
  74.  
  75.     //Clean out whatever junk is in the clipboard.
  76.     EmptyClipboard();
  77.  
  78.     //Copy private data first.
  79.     hMem=HGetPolyline(pGlob->hWndPolyline);
  80.  
  81.     //Copy private data (not "Native") we used prior to OLE.
  82.     if (NULL!=hMem)
  83.         SetClipboardData(pGlob->cfSchmoo, hMem);
  84.     else
  85.         fRet &=FALSE;
  86.  
  87. #ifdef MAKEOLESERVER
  88.  
  89.     //Copy Native data.
  90.     fRet &=FOLECopyNative(pOLE);
  91.  
  92.     //Copy "OwnerLink" data.
  93.     fRet &=FOLECopyLink(pOLE, TRUE, pGlob->szFile);
  94.  
  95. #endif //MAKEOLESERVER
  96.  
  97.     //Send the METAFILEPICT to the clipboard if we have one.
  98.     hMem=HGetMetafilePict(pGlob->hWndPolyline);
  99.  
  100.     if (NULL!=hMem)
  101.         SetClipboardData(CF_METAFILEPICT, hMem);
  102.     else
  103.         fRet &=FALSE;
  104.  
  105.     //Send the bitmap to the clipboard if we can get one.
  106.     hMem=HGetBitmap(pGlob->hWndPolyline);
  107.  
  108.     if (NULL!=hMem)
  109.         SetClipboardData(CF_BITMAP, hMem);
  110.     else
  111.         fRet &=FALSE;
  112.  
  113. #ifdef MAKEOLESERVER
  114.  
  115.     //Copy "ObjectLink" data if we have a filename AND are not cutting.
  116.     if (pGlob->fOpenFile && 0!=pGlob->szFile[0] && !fCut)
  117.         {
  118.         fRet &=FOLECopyLink(pOLE, FALSE, pGlob->szFile);
  119.         }
  120.  
  121. #endif //MAKEOLESERVER
  122.  
  123.     //Free clipboard ownership.
  124.     CloseClipboard();
  125.     return fRet;
  126.     }
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. /*
  134.  * FEditPaste
  135.  *
  136.  * Purpose:
  137.  *  Retrieves the private data format from the clipboard and sets it
  138.  *  to the current figure in the editor window.
  139.  *
  140.  *  Note that if this function is called, then the clipboard format
  141.  *  is available because the Paste menu item is only enabled if the
  142.  *  format is present.
  143.  *
  144.  * Parameters:
  145.  *  pGlob           LPGLOBALS to the global variable block.
  146.  *
  147.  * Return Value:
  148.  *  BOOL            TRUE if successful, FALSE otherwise.
  149.  *
  150.  */
  151.  
  152. BOOL FAR PASCAL FEditPaste(LPGLOBALS pGlob)
  153.     {
  154.     HANDLE          hMem;
  155.     LPPOLYLINE      lppl;
  156.  
  157.     //Attempt to gain clipboard ownership.
  158.     if (!OpenClipboard(pGlob->hWnd))
  159.         return FALSE;
  160.  
  161.     hMem=GetClipboardData(pGlob->cfSchmoo);
  162.  
  163.     if (NULL==hMem)
  164.         {
  165.         CloseClipboard();
  166.         return FALSE;
  167.         }
  168.  
  169.     lppl=(LPPOLYLINE)GlobalLock(hMem);
  170.  
  171.     //TRUE in wParam to cause PLN_SIZECHANGE notification
  172.     SendMessage(pGlob->hWndPolyline, PLM_POLYLINESET, TRUE, (LONG)lppl);
  173.     GlobalUnlock(hMem);
  174.  
  175.     FDirtySet(TRUE);
  176.     CloseClipboard();
  177.     return TRUE;
  178.     }
  179.  
  180.  
  181.  
  182. /*
  183.  * HGetPolyline
  184.  *
  185.  * Purpose:
  186.  *  Allocates global memory and copies the current Polyline into it.
  187.  *
  188.  * Parameters:
  189.  *  hWnd            HWND of the PolyLine window whose data we want.
  190.  *
  191.  * Return Value:
  192.  *  HANDLE          Global handle if successful, NULL otherwise.
  193.  */
  194.  
  195. HANDLE FAR PASCAL HGetPolyline(HWND hWnd)
  196.     {
  197.     LPPOLYLINE  lppl;
  198.     HANDLE      hMem;
  199.  
  200.     //Allocate a copy of the POLYLINE structure and set it as private data.
  201.     hMem=GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, CBPOLYLINE);
  202.  
  203.     if (NULL!=hMem)
  204.         {
  205.         lppl=(LPPOLYLINE)GlobalLock(hMem);
  206.         SendMessage(hWnd, PLM_POLYLINEGET, 0, (LONG)lppl);
  207.         GlobalUnlock(hMem);
  208.         }
  209.  
  210.     return hMem;
  211.     }
  212.  
  213.  
  214.  
  215. /*
  216.  * HGetMetafilePict
  217.  *
  218.  * Purpose:
  219.  *  Retrieves a metafile for the current polyline image.
  220.  *
  221.  * Parameters:
  222.  *  hWnd            HWND of the PolyLine window whose image we want.
  223.  *
  224.  * Return Value:
  225.  *  HANDLE          Global handle to a METAFILEPICT structure if
  226.  *                  successful, NULL otherwise.
  227.  */
  228.  
  229. HANDLE FAR PASCAL HGetMetafilePict(HWND hWnd)
  230.     {
  231.     HANDLE      hMem;
  232.     DWORD       dw;
  233.  
  234.     //Retrieve a METAFILEPICT structure for this object.
  235.     dw=SendMessage(hWnd, PLM_METAFILEPICTGET, 0, 0L);
  236.     hMem=LOWORD(dw);
  237.  
  238.     return hMem;
  239.     }
  240.  
  241.  
  242.  
  243.  
  244. /*
  245.  * HGetBitmap
  246.  *
  247.  * Purpose:
  248.  *  Retrieves a device-dependent bitmap for the current polyline image.
  249.  *
  250.  * Parameters:
  251.  *  hWnd            HWND of the PolyLine window whose image we want.
  252.  *
  253.  * Return Value:
  254.  *  HANDLE          Bitmap handle if successful, NULL otherwise.
  255.  */
  256.  
  257. HANDLE FAR PASCAL HGetBitmap(HWND hWnd)
  258.     {
  259.     HANDLE      hMem;
  260.     DWORD       dw;
  261.  
  262.     dw=SendMessage(hWnd, PLM_BITMAPGET, 0, 0L);
  263.     hMem=LOWORD(dw);
  264.  
  265.     return hMem;
  266.     }
  267.